#ifndef WALKAWARE_SHARED_DETAIL_POINTCLOUDPRIVATE_H
#define WALKAWARE_SHARED_DETAIL_POINTCLOUDPRIVATE_H

#include <assert.h>

#include <QVector>
#include <QSharedData>

#include <WalkaWare/Shared/Vec3.h>
#include <WalkaWare/Shared/Box3.h>

namespace WalkaWare
{

namespace Shared
{

namespace Detail
{

class PointCloudPrivate : public QSharedData
{
	public:

		typedef QSharedData       BaseType;
		typedef PointCloudPrivate ThisType;

		PointCloudPrivate(void)
		{
			;
		}

		PointCloudPrivate(const ThisType & other)
			: BaseType (other)
			, pts      (other.pts)
		{
			this->bbox.SetNull();
		}

		~PointCloudPrivate(void)
		{
			;
		}

		void clear(void)
		{
			this->pts.clear();
		}

		int size(void) const
		{
			return this->pts.size();
		}

		bool isEmpty(void) const
		{
			return this->pts.empty();
		}

		void updateBoundingBox(void)
		{
			const int n = this->size();
			Box3f & b = this->bbox;
			b.SetNull();
			for (int i=0; i<n; ++i)
			{
				b.Add(this->pts[i]);
			}
		}

		const Box3f & boundingBox(void) const
		{
			return this->bbox;
		}

		Box3f & boundingBox(void)
		{
			return this->bbox;
		}

		const QVector<Vec3f> & points(void) const
		{
			return this->pts;
		}

		QVector<Vec3f> & points(void)
		{
			return this->pts;
		}

		const Vec3f & at(int index) const
		{
			assert((index >= 0) && (index < this->size()));
			return this->pts[index];
		}

		Vec3f & at(int index)
		{
			assert((index >= 0) && (index < this->size()));
			return this->pts[index];
		}

		const Vec3f & operator [] (int index) const
		{
			return this->at(index);
		}

		Vec3f & operator [] (int index)
		{
			return this->at(index);
		}

		const Vec3f & operator () (int index) const
		{
			return this->at(index);
		}

		Vec3f & operator () (int index)
		{
			return this->at(index);
		}

	protected:

		QVector<Vec3f> pts;
		Box3f          bbox;
};

} // end namespace Detail

} // end namespace Shared

} // end namespace WalkaWare

#endif // WALKAWARE_SHARED_DETAIL_POINTCLOUDPRIVATE_H
